#include "ScalingBar.h"

ScalingBar::ScalingBar(int _posX, int _posY, int _frameX, int _frameY, int _width, int _height, std::string _fileName)
	: SDLSprite(_posX, _posY, _frameX, _frameY, _width, _height, _fileName), m_LastRatio(-1.0f)
{
	m_BaseWidth = m_Width;
}

ScalingBar::ScalingBar(int _posX, int _posY, int _frameX, int _frameY, int _width, int _height, std::string _fileName, Pokemon* _pokemon, SDLScene* _scene)
	: SDLSprite(_posX, _posY, _frameX, _frameY, _width, _height, _fileName, _scene), m_LastRatio(-1.0f)
{
	m_BaseWidth = m_Width;
}

ScalingBar::~ScalingBar()
{

}

void ScalingBar::Update()
{
	if(m_Pokemon != 0)
	{
		float ratio = m_Current/(float)m_Max;

		if(abs(ratio - m_LastRatio) > EPSILON)
		{
			SetFrame(m_PosX, m_PosY, m_FrameX, m_FrameY, (int)(m_BaseWidth * ratio), m_Height);
			m_LastRatio = ratio;
		}
	}
}